package com.icw.resource.workflow.entity;

import javax.persistence.*;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import com.icw.basis.BasePoEntity;
import static com.icw.configuration.ConstSettings.*;

import java.util.Set;

import com.icw.resource.inner.entity.IcwRole;
import com.icw.resource.inner.entity.IcwUser;

import lombok.*;

@Getter
@Setter
@Entity
public class WorkFlowDefinition extends BasePoEntity {

	private static final long serialVersionUID = 1L;

	@Column(length = MEDIUM_LENGTH, nullable = false)
	private String name;

	@Fetch(FetchMode.JOIN)
	@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@JoinColumn(nullable = false)
	private WorkStateDefinition initialStateDefinition;

	@Fetch(FetchMode.JOIN)
	@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
	@JoinColumn(nullable = false, insertable = true, updatable = false)
	private IcwUser builder;

	@Fetch(FetchMode.JOIN)
	@ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
	@JoinTable(joinColumns = @JoinColumn, inverseJoinColumns = @JoinColumn)
	private Set<IcwUser> allowedCreatingUsers;

	@Fetch(FetchMode.JOIN)
	@ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
	@JoinTable(joinColumns = @JoinColumn, inverseJoinColumns = @JoinColumn)
	private Set<IcwRole> allowedCreatingRoles;
}
